package com.our.base.easylog;

import java.util.ArrayList;
import java.util.List;

import org.springframework.util.StringUtils;

import com.our.base.easylog.constants.LogType;
import com.our.base.easylog.constants.PatternConstants;
import com.our.base.easylog.entity.EasyLogInfo;
import com.our.base.easylog.logback.LogbackInitializer;

/**
 * EasyLog工厂类（用于注册框架以及对应日志组件）
 *
 * @author poison
 * @DATE 2023/12/10
 **/
public class EasyLogFactory {
    private static EasyLogInfo easyLogInfo;
    private EasyLogFactory(){}

    /**
     * 根据传递的日志类型注册日志组件并保留写入到框架信息类中
     * @param logTypes 组件类型
     */
    public static void registerLogger(LogType[] logTypes,String pattern){
        if (StringUtils.isEmpty(pattern)){
            pattern= PatternConstants.LOGBACK_DEFAULT_PATTERN;
        }
        easyLogInfo=new EasyLogInfo();
        easyLogInfo.setLogTypes(logTypes);
        List<String> className=new ArrayList<>();
        for (LogType logType : logTypes) {
            switch (logType){
                case LOGBACK:
                    LogbackInitializer logbackInitializer = new LogbackInitializer(pattern);
                    className.add(logbackInitializer.getInitializerClassName());
                    break;
                default:



            }
            easyLogInfo.setRegisterClassName(className.toArray(className.toArray(new String[]{})));


        }

    }
    public static EasyLogInfo getEasyLogInfo(){
        return easyLogInfo;
    }

}
